<div class="page-body" ng-app="bannerEdit" ng-controller="formCtrl">
    <div class="row">
        <div class="widget">
            <div class="widget-body">
                <div id="horizontal-form">
                    <form class="form-horizontal" role="form"
                          action="{:U('doEdit',array('banner_id'=>$data['banner_id']))}"
                          method="post" enctype="multipart/form-data">
                        <div class="form-group">
                            <label for="title" class="col-sm-3 control-label no-padding-right">标题：</label>
                            <div class="col-sm-3">
                                <input type="text" class="form-control" id="title" name="title" value="{$data.title}"
                                       required>
                            </div>
                        </div>
                        <div class="form-group   ">
                            <label class="col-sm-3 control-label no-padding-right">图片：</label>
                            <div class="col-sm-3">
                                <input type="file" name="pic_path">
                                <notempty name="data.pic_path">
                                    <br><img src="{$data.pic_path}">
                                </notempty>
                            </div>
                        </div>
                        <div class="form-group   ">
                            <label class="col-sm-3 control-label no-padding-right">排序：</label>
                            <div class="col-sm-3">
                                <input type="number" name="sort" class="form-control" value="{$data.sort|default=0}">
                            </div>
                            <div class="col-sm-6">
                                <span class="danger">注意：>0时会显示在首页轮播中，并从大到小排</span>
                            </div>
                        </div>
                        <div class="form-group   ">
                            <label class="col-sm-3 control-label no-padding-right">链接类型：</label>
                            <div class="col-sm-3">
                                <select class="form-control" ng-model="type">
                                    <option value="0">不链接</option>
                                    <option value="book">图书</option>
                                    <option value="activity">活动</option>
                                    <option value="video">视频</option>
                                    <!--<option value="url">外链</option>-->
                                </select>
                                <input type="text" class="form-control"
                                       placeholder="{{placeholder}}"
                                       ng-model="value">
                                <span class="danger">注：请填写对应项目ID</span>
                            </div>
                        </div>
                        <div class="form-group   ">
                            <label class="col-sm-3 control-label no-padding-right">预览url：</label>
                            <div class="col-sm-9">
                                <a href="{{url()}}" target="_blank">{{url()}}</a>
                                <input type="hidden" name="url" value="{{url()}}">
                            </div>
                        </div>

                        <div class="form-group  ">
                            <div class="col-sm-offset-3 col-sm-10">
                                <button type="submit" class="btn btn-primary">提 交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var app = angular.module('bannerEdit', []);
    app.controller('formCtrl', function ($scope) {
        $scope.url = function () {
            var url = "{$data.url}";
            switch ($scope.type) {
                case "0":
                    url = "";
                    $scope.placeholder = "";
                    break;
                case "book":
                    url = "{:U('Wechat/Book/detail')}" + "/id/" + $scope.value;
                    $scope.placeholder = "图书ID";
                    if (!$scope.value) {
                        url = "";
                    }
                    break;
                case "activity":
                    url = "{:U('Wechat/Activity/detail')}" + "/id/" + $scope.value;
                    $scope.placeholder = "活动ID";
                    if (!$scope.value) {
                        url = "";
                    }
                    break;
                case "video":
                    url = "{:U('Wechat/Video/detail')}" + "/id/" + $scope.value;
                    $scope.placeholder = "视频ID";
                    if (!$scope.value) {
                        url = "";
                    }
                    break;
            }

            return url;
        }
    });
</script>